package com.android.plc.ui.manager;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;

import com.android.plc.R;
import com.android.plc.classholder.BasicItem;
import com.android.plc.provider.PLC;
import com.android.plc.provider.PLC.Rooms;
import com.android.plc.ui.IBaseManager;
import com.android.plc.ui.adapter.EditorAdapter;
import com.android.plc.ui.adapter.RoomAdapter;

public class RoomListManager implements IBaseManager
{
	private EditorAdapter mRoomList;
	private Context mContext;

	public RoomListManager(Context context)
	{
		mContext = context;
		initAdapter(null);
	}

	private void initAdapter(BasicItem room)
	{
		Cursor cursor_new = query(room);
		if (mRoomList == null)
		{
			mRoomList = new RoomAdapter(mContext, cursor_new, R.layout.room_item, new String[] { Rooms.NAME },
					new int[] { R.id.title }, false);
		} else
		{
			mRoomList.getCursor().close();
			mRoomList.setCursor(cursor_new);
		}

	}

	public void onBasicItemSelected(Manager mgr, BasicItem item, boolean admin)
	{
	}

	public void setAdapter(EditorAdapter mDeviceList)
	{
		this.mRoomList = mDeviceList;
	}

	public EditorAdapter getAdapter()
	{
		return mRoomList;
	}

	public Cursor query(BasicItem room)
	{
		ContentResolver resolver = mContext.getContentResolver();
		return resolver.query(PLC.Rooms.CONTENT_URI, PLC.ROOMS_PROJECTION, null, null, null);

	}
}